#!/bin/bash
OPTION=$1
APACHE_PORT=80
Total_Accesses(){
	/usr/bin/curl -s "http://127.0.0.1:"$APACHE_PORT"/Server_Status?auto/"|awk -F : '/Accesses/{print $2}'|cut -d" " -f 2
}
Total_KBytes(){
	  /usr/bin/curl -s "http://127.0.0.1:"$APACHE_PORT"/Server_Status?auto/"|awk -F : '/kBytes/{print $2}'|cut -d" " -f 2
}
CPULoad(){
	  /usr/bin/curl -s "http://127.0.0.1:"$APACHE_PORT"/Server_Status?auto/"|awk -F : '/CPULoad/{print $2}'|cut -d" " -f 2
}
Uptime(){
	  /usr/bin/curl -s "http://127.0.0.1:"$APACHE_PORT"/Server_Status?auto/"|awk -F : '/Uptime/{print $2}'|cut -d" " -f 2
}
ReqPerSec(){
	  /usr/bin/curl -s "http://127.0.0.1:"$APACHE_PORT"/Server_Status?auto/"|awk -F : '/ReqPerSec/{print $2}'|cut -d" " -f 2
}
BytesPerSec(){
	  /usr/bin/curl -s "http://127.0.0.1:"$APACHE_PORT"/Server_Status?auto/"|awk -F : '/BytesPerSec/{print $2}'|cut -d" " -f 2
}
BytesPerReq(){
	  /usr/bin/curl -s "http://127.0.0.1:"$APACHE_PORT"/Server_Status?auto/"|awk -F : '/BytesPerReq/{print $2}'|cut -d" " -f 2
}
BusyWorkers(){
	  /usr/bin/curl -s "http://127.0.0.1:"$APACHE_PORT"/Server_Status?auto/"|awk -F : '/BusyWorkers/{print $2}'|cut -d" " -f 2
}
IdleWorkers(){
	/usr/bin/curl -s "http://127.0.0.1:"$APACHE_PORT"/Server_Status?auto/"|awk -F : '/IdleWorkers/{print $2}'|cut -d" " -f 2
}
WaitingforConnection(){
	/usr/bin/curl -s "http://127.0.0.1/Server_Status?auto/"|awk '/^Scoreboard:/ {print split($2,notused,"_")-1}'
}
StartingUp(){
	/usr/bin/curl -s "http://127.0.0.1/Server_Status?auto/"|awk '/^Scoreboard:/ {print split($2,notused,"S")-1}'
}
ReadingRequest(){
	 /usr/bin/curl -s "http://127.0.0.1/Server_Status?auto/"|awk '/^Scoreboard:/ {print split($2,notused,"R")-1}'
}
SendingReply(){
       /usr/bin/curl -s "http://127.0.0.1/Server_Status?auto/"|awk '/^Scoreboard:/ {print split($2,notused,"W")-1}'
}
Keepalive(){
       /usr/bin/curl -s "http://127.0.0.1/Server_Status?auto/"|awk '/^Scoreboard:/ {print split($2,notused,"K")-1}'
}
DNSLookup(){
	/usr/bin/curl -s "http://127.0.0.1/Server_Status?auto/"|awk '/^Scoreboard:/ {print split($2,notused,"D")-1}'
}
ClosingConnection(){
	 /usr/bin/curl -s "http://127.0.0.1/Server_Status?auto/"|awk '/^Scoreboard:/ {print split($2,notused,"C")-1}'
}
Logging(){
	/usr/bin/curl -s "http://127.0.0.1/Server_Status?auto/"|awk '/^Scoreboard:/ {print split($2,notused,"L")-1}'
}
GracefullyFinishing(){
	    /usr/bin/curl -s "http://127.0.0.1/Server_Status?auto/"|awk '/^Scoreboard:/ {print split($2,notused,"G")-1}'
}
IdleCleanupOfWorker(){
    /usr/bin/curl -s "http://127.0.0.1/Server_Status?auto/"|awk '/^Scoreboard:/ {print split($2,notused,"I")-1}'
}
OpenSlotWithNoCurrentProcess(){
	  /usr/bin/curl -s "http://127.0.0.1/Server_Status?auto/"|awk '/^Scoreboard:/ {print split($2,notused,".")-1}'
}
Check_Port(){
	if [ `ps -ef|grep httpd|grep -v grep|wc -l` -gt 1 ];then
		echo "0"
	else
		echo "1"
	fi
}

case $OPTION in
	TotalAccesses)
		Total_Accesses
		;;
	TotalKBytes)
		Total_KBytes
		;;
	CPULoad)
		CPULoad
		;;
	Uptime)
		Uptime
		;;
	ReqPerSec)
		ReqPerSec
		;;
	BytesPerSec)
		BytesPerSec
		;;
	BytesPerReq)
		BytesPerReq
		;;
	BusyWorkers)
		BusyWorkers
		;;
	IdleWorkers)
		IdleWorkers
		;;
	WaitingforConnection)
		WaitingforConnection
		;;
	StartingUp)
		StartingUp
		;;
	ReadingRequest)
		ReadingRequest
		;;
	SendingReply)
		SendingReply
		;;
	Keepalive)
		Keepalive
		;;
	DNSLookup)
		DNSLookup
		;;
	ClosingConnection)
		ClosingConnection
		;;
	Logging)
		Logging
		;;
	GracefullyFinishing)
		GracefullyFinishing
		;;
	IdleCleanupOfWorker)
		IdleCleanupOfWorker
		;;
	OpenSlotWithNoCurrentProcess)
		OpenSlotWithNoCurrentProcess
		;;
	CheckPort)
		Check_Port
		;;
	*)
		echo $"USAGE:$0 {CheckPort|OpenSlotWithNoCurrentProcess|IdleCleanupOfWorker|GracefullyFinishing|Logging|ClosingConnection|DNSLookup|Keepalive|SendingReply|ReadingRequest|StartingUp|WaitingforConnection|IdleWorkers|BusyWorkers|BytesPerReq|BytesPerSec|ReqPerSec|TotalAccesses|TotalKBytes|CPULoad|Uptime"
esac
